<template>
  <app-card title="告警事件分布">
    <div class="item" v-for="(item, index) in data">
      <div class="head">
        <div class="index">{{ index + 1 }}</div>
        <div class="title">{{ item.attck_type }}</div>
        <div class="value">{{ item.size }}</div>
      </div>

      <div class="progress">
        <div class="bar" :style="{ width: `${max ? (item.size / max) * 100 : 0}%` }"></div>
      </div>
    </div>
  </app-card>
</template>
<script setup>
const props = defineProps({
  data: Object,
})

const max = computed(() => {
  return Math.max(...props.data.map(item => item.size))
})
</script>
<style lang="scss" scoped>
.item {
  padding: 8px;
  border-radius: 6px;
  &:hover {
    background-color: #f8fafc;
  }
}
.head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  .index {
    width: 32px;
    height: 32px;
    color: #fff;
    border-radius: 100%;
    background-color: #ef4444;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700px;
  }
  .title {
    flex: 1;
    font-weight: 500;
  }
  .value {
    color: #475569;
    font-weight: 700px;
  }
}
.progress {
  background-color: #e2e8f0;
  width: 100%;
  height: 8px;
  border-radius: 4px;
  position: relative;
  overflow: hidden;
  .bar {
    position: absolute;
    background-color: #ef4444;
    top: 0;
    left: 0;
    height: 100%;
  }
}
</style>
